<?php

namespace app\service\admin;

use app\service\base\BaseModel;
use think\facade\Db;

class AdminRoleModel extends BaseModel
{
    protected $name = 'admin_role';

    public function getPage($arrWhere, $limit)
    {
        return Db::name($this->name)
            ->field('*')
            ->where($arrWhere)
            ->paginate($limit)
            ->toArray();
    }

    public function getAll()
    {
        return Db::name($this->name)->field('*')->select()->toArray();
    }

    public function getRow($arrWhere)
    {
        return Db::name($this->name)->where($arrWhere)->find();
    }

    public function add($name, $desc)
    {
        $arrData               = [];
        $arrData['name']       = $name;
        $arrData['desc']       = $desc;
        $arrData['create_dt'] = date('Y-m-d H:i:s');
        $arrData['update_dt'] = date('Y-m-d H:i:s');
        return Db::name($this->name)->insertGetId($arrData);
    }

    public function edit($id, $name, $desc)
    {
        $arrData               = [];
        $arrData['name']       = $name;
        $arrData['desc']       = $desc;
        $arrData['update_dt'] = date('Y-m-d H:i:s');
        return Db::name($this->name)->where('id', $id)->update($arrData);
    }

    public function delById($id)
    {
        return Db::name($this->name)->where('id', $id)->delete();
    }
}